package com.example.music;

import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import android.os.Environment;


public class Manager {
	
	/**
	 * 判断SD卡是否插入
	 */
	public static boolean SDcardExist() {
		return Environment.getExternalStorageState().equals(
				android.os.Environment.MEDIA_MOUNTED);
	}

	/**
	 * 获得sd卡根目录
	 */
	public static File getSDcardROOT() {
		File sdRoot = Environment.getExternalStorageDirectory();
		return sdRoot;
	}

	/**
	 * 获取文章夹下文件
	 * @param file
	 * @return
	 */
	public static List<Map<String, Object>> getData(File file) { // 将目录数据填充到链表中
		List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
		Map<String, Object> map = null;
		File[] files = file.listFiles(); // 获取当前目录中文件列表

		if (files != null) { // 将目录中文件填加到列表中
			for (int i = 0; i < files.length; i++) {
				map = new HashMap<String, Object>();
				map.put("filename", files[i].getName());
				map.put("filepath", files[i].getPath());
				map.put("filetype", R.drawable.ic_launcher);
				list.add(map);
			}
		}
		return list;
	}
}
